// Package requests 处理对话表单验证
package requests

import (
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type ChatMessage struct {
	Role    string `json:"role" binding:"required"`
	Content string `json:"content" binding:"required"`
}

type ChatRequest struct {
	Model       string        `json:"model" binding:"required"`
	Messages    []ChatMessage `json:"messages" binding:"required"`
	Temperature float32       `json:"temperature,omitempty"`
	MaxTokens   int           `json:"max_tokens,omitempty"`
	Stream      bool          `json:"stream,omitempty"`
}

// 验证表单，返回长度等于0即通过
func VerifyChatRequest(data interface{}, c *gin.Context) map[string][]string {

	// 1. 定制验证规则
	rules := govalidator.MapData{
		"model": []string{"required"},
	}

	// 2. 定制错误消息
	messages := govalidator.MapData{
		"model": []string{
			"required:model 为必填",
		},
	}

	errs := validate(data, rules, messages)

	return errs
}
